#!/usr/bin/python3

import os
import sys

path = "."
if len(sys.argv) > 1:
    path = sys.argv[1]
cwd = os.getcwd()

os.path.join(os.getcwd(), path)


def getDirsize(path):
    print(path)
    if os.path.isdir(path):
        name_list = os.listdir(path)
        name_list = [os.path.join(path, n) for n in name_list]
        return sum(map(lambda name: getDirsize(name), name_list)) \
            + os.path.getsize(path)
    elif os.path.isfile(path):
        return os.path.getsize(path)
    elif os.path.islink(path):
        return getDirsize(os.readlink(path))
    else:
        # mute the unexpected file type
        return 0


print(getDirsize(path))
